** Do File for Tables 1 and 2 and some online appendix tables in Layman, Campbell, Green, & Sumaktoyo, "Secularism and American Political Behavior" in Public Opinion Quarterly**

**Open 2017 Secularism Survey data (note: change file location to match where you have saved the data)
use "C:\Users\glayman\Dropbox\Secularism Project\POQ submission\Replication Files\Secularism Survey 2017_POQ.dta", clear

** recoding religious and secular IDs **
recode ID_ECUMEN 2=0, gen(ID_ECUMEN2)
recode ID_MAINLINE 2=0, gen(ID_MAINLINE2)
recode ID_CHAR 2=0, gen(ID_CHAR2)
recode ID_HUM 2=0, gen(ID_HUM2)
recode ID_NONTRAD 2=0, gen(ID_NONTRAD2)
recode ID_SEC 2=0, gen(ID_SEC2)
recode ID_ATHEIST 2=0, gen(ID_ATHEIST2)
recode ID_FUND 2=0, gen(ID_FUND2)
recode ID_EVAN 2=0, gen(ID_EVAN2)
recode ID_AGNOSTIC 2=0, gen(ID_AGNOSTIC2)
recode ID_SBNR 2=0, gen(ID_SBNR2)
recode ID_NONE 2=0, gen(ID_NONE2)

**Creating New Atheist and Agnostic IDs for people who identified as atheist or agnostic either in 
**the religious affiliation question or in the ID battery
gen ID_ATH2_2=0
gen ID_AGNOS2_2=0
replace ID_ATH2_2=1 if ID_ATHEIST2==1 | REL_PRESENT==9
replace ID_AGNOS2_2=1 if ID_AGNOSTIC2==1 | REL_PRESENT==10
label var ID_ATH2_2 "Atheist either in relig affiliation or IDs"
label var ID_AGNOS2_2 "Agnostic either in relig affiliation of IDs"

**Table A3 analysis: Factor analysis of religious and secular identities
factor ID_ECUMEN2 ID_MAINLINE2 ID_CHAR2 ID_FUND2 ID_EVAN2 ID_NONTRAD2 ID_SBNR2 ID_HUM2 ID_SEC2 ID_ATH2_2 ID_AGNOS2_2 [aweight=weight], pcf
rotate, promax

**Secular Identity Count **
gen secidnum= ID_HUM2+ ID_SEC2+ ID_ATH2_2+ ID_AGNOS2_2
label var secidnum "# of secular IDs selected: ID_HUM2+ ID_SEC2+ ID_ATH2_2+ ID_AGNOS2_2"
gen secidnum01=secidnum/4

** religious and secular guidance **
gen relguide01=1-(relguide/3)
gen nonrelguide01=nonrelguide/3

** Recoding secular beliefs to range from 0 to 1 **
** Also reversed coding so that all range from strongly disagree to strongly agree **
gen factual01=1-((factual-1)/4)
gen philosci01=1-((PHILO_SCIENCE-1)/4)
gen reason01=1-((reason-1)/4)
gen freemind01=1-((freeminds-1)/4)
gen decision01=1-((decision-1)/4)
gen advances01=1-((advances-1)/4)
gen knowledge01=1-((knowledge-1)/4)
gen problems01=1-((problems-1)/4)

**Recoding religiosity indicators to range from 0 to 1**
**Reverse some items so that higher scores = more secular**
gen relatt01=(relattend-1)/8
gen pray01=(pray-1)/8
gen god01=1-(god_rule/100)
gen bible01=(bible-1)/3

**Creating variable for nothing in particular (none) and all nones (including atheists and agnostics)
recode REL_PRESENT 1/10=0 11=1 12=0, gen(none)
label var none "nothing in particular only"
gen allnone=0
replace allnone=1 if REL_PRESENT>8 & REL_PRESENT<12

**Table A5 analysis: factor analysis of non-religiosity and secularism indicators**
factor relatt01 relguide01 pray01 god01 bible01 none factual01 philosci01 reason01 freemind01 decision01 advances01 knowledge01 problems01 nonrelguide01 secidnum01 [aweight=weight], pcf
rotate, promax

**Demographic variables
gen white=0
replace white=1 if race==1

** Coding Religious Tradition (RELTRAD) **
label define reltrad 1 "Evangelical" 2 "Mainline" 3 "Black Protestants" 4 "Catholic" 5 "Mormon" 6 "Eastern/Greek Orthodox" 7 "Jewish" 8 "Muslim" 9 "Buddhist" 10 "Hindu" 11 "Other" 12 "None" 13 "Atheist" 14 "Agnostic"


gen reltrad =.
recode reltrad .=4 if REL_PRESENT ==2
recode reltrad .=5 if REL_PRESENT ==3
recode reltrad .=6 if REL_PRESENT== 4
recode reltrad .=7 if REL_PRESENT == 5
recode reltrad .=8 if REL_PRESENT == 6
recode reltrad .=9 if REL_PRESENT == 7
recode reltrad .=10 if REL_PRESENT == 8
recode reltrad .=12 if REL_PRESENT == 11
recode reltrad .=13 if REL_PRESENT == 9
recode reltrad .=14 if REL_PRESENT == 10

label value reltrad reltrad

** coding evangelicals **

recode reltrad .=1 if baptist ==1
recode reltrad .=1 if (baptist >2 & baptist < 91)
** coded all "Other Baptists" as evangelicals, did not use open-ended **
recode reltrad .=1 if methodist ==4
recode reltrad .=1 if nondenom ==1 | nondenom==2 | nondenom==3
recode reltrad .=1 if lutheran ==2 | lutheran ==3
recode reltrad .=1 if presbyterian == 2 | presbyterian ==3 | presbyterian ==6
** coded Associate Reformed Presbyterian as evangelical **
recode reltrad .=1 if episcopalian == 3 | episcopalian ==4
**coded Anglican Orthodox and Reformed Episcopal as evangelical **
recode reltrad .=1 if christian ==1 | christian ==3
** church of christ, christian churches/churches of christ **
recode reltrad .=1 if reformed ==2 
recode reltrad .=1 if protdenom == 8 | protdenom ==9 | protdenom ==10

** coding open-ended responses **
recode reltrad .=1 if  PROTDENOM_t == "Apostolic" ///
|  PROTDENOM_t =="Calvary Chapel" ///
|  PROTDENOM_t =="Christian and Missionary Alliance" ///
|  PROTDENOM_t =="Church of God" ///
|  PROTDENOM_t =="Church of the Brethren" ///
|  PROTDENOM_t =="Evangelical" ///
|  PROTDENOM_t =="Evangelical Free Church of America (EFCA)" ///
|  PROTDENOM_t =="Evangelistic" ///
|  PROTDENOM_t =="Missionary Baptist" ///
|  PROTDENOM_t =="Nazarene" ///
|  PROTDENOM_t =="Seventh day Adventist" | PROTDENOM_t =="Seventh day adventist" | PROTDENOM_t == "Seventh-day Adventist" ///
|  PROTDENOM_t =="The First Christian Fellowship of Eternal Sovereignty" ///
|  PROTDENOM_t =="Wesleyan" ///
|  PROTDENOM_t =="assemblies of god" ///
|  PROTDENOM_t =="primitive Baptist" ///
|  PROTDENOM_t =="seventh day pentecostal"

recode reltrad .=1 if METHODIST_t =="pentecostal"
recode reltrad .=1 if NONDENOM_t =="Assembly of god" ///
| NONDENOM_t =="Bible Christian" ///
| NONDENOM_t =="Biblical research" ///
| NONDENOM_t == "Nondenominational Holiness Church" 

recode reltrad .=1 if REFORMED_t == "Dutch" | REFORMED_t == "Reformed Methodist"

recode reltrad .=1 if REL_PRESENT_t == "A/G" 
recode reltrad .=1 if REL_PRESENT_t =="BAPTISIT" | REL_PRESENT_t =="BAPTIST" | REL_PRESENT_t == "Babtist" | REL_PRESENT_t == "Baltist" | REL_PRESENT_t == "Baptist"

recode reltrad .=1 if REL_PRESENT_t == "Born Again" | REL_PRESENT_t == "Born Again Christian" | REL_PRESENT_t == "Born again" | REL_PRESENT_t == "Born again Christian" | REL_PRESENT_t == "Christian Baptist"
recode reltrad .=1 if REL_PRESENT_t == "Evangelical" | REL_PRESENT_t =="Evangelical Pentecostal" | REL_PRESENT_t == "Evangelist" 
recode reltrad .=1 if REL_PRESENT_t == "First Christian Fellowship of Eternal Sovereignty"
recode reltrad .=1 if REL_PRESENT_t == "Holiness" | REL_PRESENT_t == "Hollines" | REL_PRESENT_t == "Holyness"
recode reltrad .=1 if REL_PRESENT_t == "Nazareth"
recode reltrad .=1 if REL_PRESENT_t == "PENTECOSTAL" | REL_PRESENT_t =="Pentecostal" | REL_PRESENT_t == "Pentecostal Christian" | REL_PRESENT_t =="Primitive Baptist"
recode reltrad .=1 if REL_PRESENT_t == "Seventh Day Adventist" | REL_PRESENT_t == "Seventh day Adventist" | REL_PRESENT_t == "Southern Baptist" | REL_PRESENT_t == "Spirit filled Christian"
recode reltrad .=1 if REL_PRESENT_t == "Wisconsin Evangelical Lutheran Synod"
recode reltrad .=1 if REL_PRESENT_t =="adventist"
recode reltrad .=1 if REL_PRESENT_t =="baptis" | REL_PRESENT_t =="baptist" | REL_PRESENT_t =="baptiste" | REL_PRESENT_t =="baptists" | REL_PRESENT_t =="bastipist" ///
| REL_PRESENT_t =="beptist" | REL_PRESENT_t == "bisptist" | REL_PRESENT_t == "born again christian" | REL_PRESENT_t == "evangelic" | REL_PRESENT_t =="funamentalist" 
recode reltrad .=1 if REL_PRESENT_t =="pentosal"

** coding mainline Protestants **
recode reltrad .=2 if baptist==2
recode reltrad .=2 if methodist ==1 
recode reltrad .=2 if lutheran ==1 | lutheran ==90
** coded all "Other Lutheran" as mainline; did not use open-ended **
recode reltrad .=2 if presbyterian ==1 | presbyterian ==90
recode reltrad .=2 if episcopalian ==1 | episcopalian ==5 | episcopalian == 90
recode reltrad .=2 if christian ==2
recode reltrad .=2 if reformed ==1

**coding open-ended responses **
recode reltrad .=2 if PROTDENOM_t =="Angelican"
recode reltrad .=2 if PROTDENOM_t =="Church of Scotland"
recode reltrad .=2 if PROTDENOM_t =="Community of Christ (formerly the Reorganized Church of Jesus Christ of Latter Day Saints - or RLDS)"
recode reltrad .=2 if PROTDENOM_t =="RLDS"

recode reltrad .=2 if METHODIST_t== "Evangelical united Methodist church"
recode reltrad .=2 if PRESBYTERIAN_t == "Currently looking for a church"
recode reltrad .=2 if PRESBYTERIAN_t == "I don't know"
recode reltrad .=2 if EPISCOPALIAN_t == "St Simons"
recode reltrad .=2 if REFORMED_t== "Reformed Methodist" | REFORMED_t== "United Church of Christ" | REFORMED_t== "non-denominattional"

recode reltrad .=2 if REL_PRESENT_t == "Anglican"
recode reltrad .=2 if REL_PRESENT_t == "Christian(Disciples of Christ)"
recode reltrad .=2 if REL_PRESENT_t == "Church of Christ" 
recode reltrad .=2 if REL_PRESENT_t == "Community of Christ (formerly the Reorganized Church of Jesus Christ of Latter Day Saints - or RLDS)"
recode reltrad .=2 if REL_PRESENT_t == "Episcopalian"
recode reltrad .=2 if REL_PRESENT_t == "Lutheran"
recode reltrad .=2 if REL_PRESENT_t == "Methodist"
recode reltrad .=2 if REL_PRESENT_t == "Methodr"
recode reltrad .=2 if REL_PRESENT_t == "RLDS"
recode reltrad .=2 if REL_PRESENT_t =="Raised presbyterian"
recode reltrad .=2 if REL_PRESENT_t == "episcopalian"
recode reltrad .=2 if REL_PRESENT_t == "lutheran"
recode reltrad .=2 if REL_PRESENT_t == "luthern"
recode reltrad .=2 if REL_PRESENT_t == "methodist" | REL_PRESENT_t == "metholist"
recode reltrad .=2 if REL_PRESENT_t =="non denominational church of christ"

** coding Black Protestants **
recode reltrad .=3 if methodist == 3 | methodist ==4
recode reltrad .=3 if PROTDENOM_t =="baptist/ AME" 
recode reltrad .=3 if REL_PRESENT_t == "AME" | REL_PRESENT_t == "African Methodist Episcopal"
recode reltrad .=3 if REL_PRESENT_t == "Church of Christ (old southern)"
recode reltrad .=3 if REL_PRESENT_t == "baptist/ AME"

** coding open-ended responses **
recode reltrad .=3 if PROTDENOM_t == "African Methodist Episcopal"


** coding Eastern Orthodox **
recode reltrad .=6 if PROTDENOM_t == "Armenian Apostolic"
recode reltrad .=6 if REL_PRESENT_t == "Armenian Apostolic"

** coding Other **
recode reltrad .=11 if protdenom == 12
**Jehovah's Witnesses **

recode reltrad .=11 if PROTDENOM_t == "Bahai"
recode reltrad .=11 if PROTDENOM_t =="Church of Scientology"
recode reltrad .=11 if PROTDENOM_t =="Hebraic Roots congregation"
recode reltrad .=11 if PROTDENOM_t =="None, I'm Gnostic"
recode reltrad .=11 if PROTDENOM_t =="Unitarian Universalist"
recode reltrad .=11 if NONDENOM_t == "Testigos de jehova"
recode reltrad .= 11 if NONDENOM_t == "Self Realization Fellowship"
recode reltrad .=11 if PROTDENOM_t =="Messianic"
recode reltrad .=11 if REL_PRESENT_t == "Asatru"
recode reltrad .=11 if REL_PRESENT_t == "Bahai"
recode reltrad .=11 if REL_PRESENT_t == "Communistic Pagan"
recode reltrad .=11 if REL_PRESENT_t == "Ethical Humanist"
recode reltrad .=11 if REL_PRESENT_t =="FAME"
recode reltrad .=11 if REL_PRESENT_t =="Free church" | REL_PRESENT_t == "Gnostic" | REL_PRESENT_t == "Gnostic Christian"
recode reltrad .=11 if REL_PRESENT_t =="It's complicated"
recode reltrad .=11 if REL_PRESENT_t == "Jehovah witness" | REL_PRESENT_t == "Jehovah ‘s Witnesses" | REL_PRESENT_t == "Jehovah's Witness" | REL_PRESENT_t ==  "Jehovah's Witnesses" | REL_PRESENT_t ==  "Jehovahs Witness"
recode reltrad .=11 if REL_PRESENT_t == "Jewish and Unitarian Universalist"
recode reltrad .=11 if REL_PRESENT_t =="Lakota"
recode reltrad .=11 if REL_PRESENT_t =="Messianic" | REL_PRESENT_t == "Messianic Gentile" | REL_PRESENT_t == "Messianic Judaism"
recode reltrad .=11 if REL_PRESENT_t =="Native American" | REL_PRESENT_t =="Native American /pagan" | REL_PRESENT_t == "Native American Church" | REL_PRESENT_t == "Neo-Pagan" | REL_PRESENT_t == "Neo-Pagan"
recode reltrad .=11 if REL_PRESENT_t =="Non Christian spiritual"
recode reltrad .=11 if REL_PRESENT_t == "None of your business"
recode reltrad .=11 if REL_PRESENT_t == "Norse Pagan" | REL_PRESENT_t == "Odinist" | REL_PRESENT_t == "Omnist" | REL_PRESENT_t == " Ontologist." | REL_PRESENT_t == "PAGAN" | REL_PRESENT_t =="Pagan"
recode reltrad .=11 if REL_PRESENT_t == "SPIRITUALIST"
recode reltrad .=11 if REL_PRESENT_t == "Scientology"
recode reltrad .=11 if REL_PRESENT_t == "Self Realization Fellowship"
recode reltrad .=11 if REL_PRESENT_t == "Still figuring out"
recode reltrad .=11 if REL_PRESENT_t == "Testigos de jehova"
recode reltrad .=11 if REL_PRESENT_t == "Unitarian Universalism"
recode reltrad .=11 if REL_PRESENT_t == "Unitarian Universalist" | REL_PRESENT_t =="Universal Unitarian"
recode reltrad .=11 if REL_PRESENT_t == "Wicca" | REL_PRESENT_t == "Wiccan" | REL_PRESENT_t == "Wiccian"
recode reltrad .=11 if REL_PRESENT_t == "bati"
recode reltrad .=11 if REL_PRESENT_t =="follower of Yehsua"
recode reltrad .=11 if REL_PRESENT_t == "pagan"
recode reltrad .=11 if REL_PRESENT_t == "uu"
recode reltrad .=11 if REL_PRESENT_t == "wicca " | REL_PRESENT_t == "wiccan"

** coding ambiguous Protestants **
gen ambigprot = . 
recode ambigprot .=1 if nondenom == 4 | nondenom ==5 
recode ambigprot .=1 if reformed == 90
recode ambigprot .=1 if protdenom == 13 | protdenom == 90
recode ambigprot .= 1 if PROTDENOM_t =="Christian" |  PROTDENOM_t =="Christian Church"
recode ambigprot .=1 if PROTDENOM_t =="Horizon Central"
recode ambigprot .=1 if PROTDENOM_t =="House of Jacob"
recode ambigprot .=1 if PROTDENOM_t =="Non-denominational"
recode ambigprot .=1 if PROTDENOM_t =="Watch Pastor Arnold or his son daily"
recode ambigprot .=1 if PROTDENOM_t =="christian"
recode ambigprot .=1 if PROTDENOM_t =="non denominational"
recode ambigprot .=1 if NONDENOM_t =="Christian" |  NONDENOM_t =="Don't know"
recode ambigprot .=1 if NONDENOM_t =="Other"
recode ambigprot .=1 if NONDENOM_t =="Unity"
recode ambigprot .=1 if NONDENOM_t =="Unknown - Non-Doctrinal, Scripture Teaching"
recode ambigprot .=1 if NONDENOM_t == "nondenominational"
recode ambigprot .=1 if REL_PRESENT_t == "Believer" | REL_PRESENT_t == "Believer of Christ"
recode ambigprot .=1 if REL_PRESENT_t == "CHRISTIAN"
recode ambigprot .=1 if REL_PRESENT_t == "Chirsten" | REL_PRESENT_t == "Chistian" | REL_PRESENT_t == "Christ alone" | REL_PRESENT_t == "Christain" | REL_PRESENT_t == "Christan" ///
| REL_PRESENT_t == "Christiab" | REL_PRESENT_t == "Christian" | REL_PRESENT_t == "Christian (non-denominational)" | REL_PRESENT_t == "Christian Mysticism" | REL_PRESENT_t == "Christian non dom" ///
| REL_PRESENT_t == "Christian with a broad spiritual belief" | REL_PRESENT_t == "Christian!" | REL_PRESENT_t == "Christian, Non-denomination" | REL_PRESENT_t == "Christianity" ///
| REL_PRESENT_t == "Christians" | REL_PRESENT_t == "Christin" 
recode ambigprot .=1 if REL_PRESENT_t == "I AM A CHRISTIAN" | REL_PRESENT_t == "I just consider myself a Christian" | REL_PRESENT_t =="Just a Follower of Jesus Christ True Teachings"
recode ambigprot .=1 if REL_PRESENT_t == "NONDENOMINATIONAL" | REL_PRESENT_t =="Non demonational Christian" | REL_PRESENT_t =="Non denomination Christian" | REL_PRESENT_t =="Non denominational" /// 
| REL_PRESENT_t == "Non denominational Christian" | REL_PRESENT_t == "Non religious Christian" | REL_PRESENT_t == "Non-denominational" | REL_PRESENT_t == "Non-evangelical Christian" ///
| REL_PRESENT_t == "Nondemonination" | REL_PRESENT_t == "Nondenominational" | REL_PRESENT_t == "Nondenominational Christian"
recode ambigprot .=1 if REL_PRESENT_t == "christian" | REL_PRESENT_t =="christianalllity"
recode ambigprot .=1 if REL_PRESENT_t == "non denomination christian" | REL_PRESENT_t == "non denominational" | REL_PRESENT_t == "nondenominational Christian"

** coding Mormon **
recode reltrad .=5 if  PROTDENOM_t =="Currently not attending on a regular basis but LDS church sometimes"

** coding None **
recode reltrad .= 12 if PROTDENOM_t =="Don't attend church"
recode reltrad .= 12 if PROTDENOM_t =="I do not belong to a church" | PROTDENOM_t =="I don't belong to a church" ///
| PROTDENOM_t == "I don't belong to any church group." | PROTDENOM_t =="I go as the spirit leads" ///
| PROTDENOM_t == "N/A" |  PROTDENOM_t =="NONE" | PROTDENOM_t =="NOTHING" | PROTDENOM_t =="Nature not a building" ///
| PROTDENOM_t =="No Church or group" | PROTDENOM_t =="No church" | PROTDENOM_t =="None" | PROTDENOM_t =="None of these" ///
| PROTDENOM_t =="Not affiliated" ///
| PROTDENOM_t == "Spiritual" ///
| PROTDENOM_t =="no organized religion" ///
| PROTDENOM_t =="none" ///
| PROTDENOM_t =="recovering baptist"

recode reltrad .=12 if NONDENOM_t =="I attend no church"
recode reltrad .=12 if NONDENOM_t =="I don't know. The kind that isn't trying to kill gays, is okay with first trimester abortions, and thinks we need to limit guns. I guess my own made up knid"
recode reltrad .=12 if NONDENOM_t =="N/a"
recode reltrad .=12 if NONDENOM_t =="None" | NONDENOM_t =="no church" | NONDENOM_t =="no church home" | NONDENOM_t =="none" | NONDENOM_t =="not sure" | NONDENOM_t =="nothing specific" | NONDENOM_t =="worship on my own"
recode reltrad .=12 if PRESBYTERIAN_t == "Don't belong to a particular church."
recode reltrad .=12 if PRESBYTERIAN_t == "none"
recode reltrad .=12 if EPISCOPALIAN_t == "No church"
recode reltrad .=12 if REL_PRESENT_t == "Deism" | REL_PRESENT_t == "Deist" | REL_PRESENT_t == "Diest"
recode reltrad .=12 if REL_PRESENT_t == "Humanism" | REL_PRESENT_t == "Humanist"
recode reltrad .=12 if REL_PRESENT_t =="I identify most with Wicca but I am not religious."
recode reltrad .=12 if REL_PRESENT_t ==" No"
recode reltrad .=12 if REL_PRESENT_t == "Secular Humanist"
recode reltrad .=12 if REL_PRESENT_t == "Spiritual" | REL_PRESENT_t =="Spiritual but non demonitional" | REL_PRESENT_t =="Spiritual not religious"
recode reltrad .=12 if REL_PRESENT_t =="deism"
recode reltrad .=12 if REL_PRESENT_t =="just a human that doesnt like to be labled for my lack of belief"
recode reltrad .=12 if REL_PRESENT_t =="no religiom"
recode reltrad .=12 if REL_PRESENT_t =="retired Catholic"
recode reltrad .=12 if REL_PRESENT_t =="spiritual but not religious" | REL_PRESENT_t =="spiritualist, I don't bekieve in organized religion."

** coding Catholics **
recode reltrad .=4 if PROTDENOM_t =="Catholic, nonpracticing" ///
|  PROTDENOM_t =="Catholic" ///
|  PROTDENOM_t =="I goofed on the previous question I am Roman Catholic"

recode reltrad .=4 if REL_PRESENT_t== "Catholic" | REL_PRESENT_t == "Catholic, nonpracticing" | REL_PRESENT_t =="Roman Catholic, NOT American Catholic"
recode reltrad .=4 if REL_PRESENT_t=="christain catholic"

** recoding atheists, agnostics **
recode reltrad .=13 if REL_PRESENT_t == "Agnostic atheist"
recode reltrad .=13 if REL_PRESENT_t == "Atheism is not a religion"
recode reltrad .=13 if REL_PRESENT_t == "Fair-Weather Atheistic Satanist"
recode reltrad .=13 if REL_PRESENT_t == "Feminist Atheist Quaker Jew"
recode reltrad .=13 if REL_PRESENT_t =="Jewish and atheist"
recode reltrad .=13 if REL_PRESENT_t =="antideist"
recode reltrad .=13 if REL_PRESENT_t =="non-thiest"

** coding Jews **
recode reltrad .=7 if REL_PRESENT_t == "Hebrew"

** recoding ambiguous Protestants **
recode ambigprot 1=2 if (ID_EVAN2==1 | ID_FUND2==1 | ID_TRAD2 ==1 | ID_CHAR2==1)
recode reltrad *=1 if ambigprot==2
recode reltrad *=2 if ambigprot==1

** recoding Black Protestants **
recode reltrad *=3 if race_2==1 & (reltrad==1 | reltrad==2)

**Dummies for evangelicals, mainline Protestants, and Catholics
gen evang=0 if reltrad~=.
gen mainline=0 if reltrad~=.
gen catholic=0 if reltrad~=.
replace evang=1 if reltrad==1
replace mainline=1 if reltrad==2
replace catholic=1 if reltrad==4

** recoding demographic variables to range from 0 to 1**
gen pid01 = 1-((pid7-1)/6)
gen age01 = (age-18)/74
gen educ01 = (educ-1)/5
gen income01 = (faminc_new-1)/15

** CREATING COMPARATIVE CANDIDATE EVALUATIONS VARIABLE **
gen candeval=FT_TRUMP - FT_CLINTON
gen candeval01=1-((candeval+100)/200)

**Generating region dummies
gen south=0
replace south=1 if fips_state==1 | fips_state==5 | fips_state==12 | fips_state==13| fips_state==21 | fips_state==22 | fips_state==28|fips_state==37|fips_state==40|fips_state==45|fips_state==47|fips_state==48| fips_state==51|fips_state==54
gen northeast=0
replace northeast=1 if fips_state==9 | fips_state==10 | fips_state==11 | fips_state==23 | fips_state==24 | fips_state==25 | fips_state==33 | fips_state==34 | fips_state==36 | fips_state==42 | fips_state==44 | fips_state==50
gen west=0
replace west=1 if fips_state==2 | fips_state==4 | fips_state==6 | fips_state==8 | fips_state==15 |  fips_state==16 |  fips_state==30 |  fips_state==32 |  fips_state==35 |  fips_state==41 |  fips_state==49 |  fips_state==53 |  fips_state==56 
gen midwest=0
replace midwest=1 if south==0 & northeast==0 & west==0

**Recoding issue and participation variables to range from 0 to 1**
gen govserv01=govserv/100
gen govinv01=1-(govinv/100)
gen health01=1-(health/100)
gen gaywed01=gaywed/100
gen gaytherm01=FT_GAY/100
gen sexed01=(sexed-1)/4
gen scitech01=1-((scitech-1)/4)
gen enviro01=enviro/100
gen evol01=1-((evol-1)/4)
gen globwarm01=1-((globwarm-1)/4)
gen vaccine01=1-((vaccine-1)/4)
gen immig01=1-(immig/100)
gen world01=1-(world/100)
gen camprally=camp_rally2/2
gen camptalk=camp_talk2/2
gen campbutton=camp_button2/2
gen campwork=camp_work2/2
gen campmoney=camp_money2/2
gen effnosay=(EFF_NOSAY-1)/4

**Public secularism variables, recoding to 0 to 1**
gen prespray=PRES_PRAY_rule/100
gen prestalk=PRES_TALK_rule/100
gen presendorse=PRES_ENDORSE_rule/100
gen presgod=PRES_GODOATH_rule/100
gen estpledge=(EST_PLEDGE-1)/4
gen estten=(EST_TEN-1)/4
gen estprayer=(EST_PRAYER-1)/4
gen estoffrel=(EST_OFFREL-1)/4

**Drop old and unnecessary variables
drop REL_PRESENT-birthyr race-faminc_new pid7-camp_money2 fips_state protdenom-secidnum reltrad ambigprot candeval midwest

**Save new version of 2017 Secularism Survey data (note: change file location to match where you are saving these data)
save "C:\Users\glayman\Dropbox\Secularism Project\POQ submission\Replication Files\Secularism Survey 2017_POQ_new.dta", replace

**Drop variables that are only for the political participation model and other models, leaving data for all other analyses in Table 2, Table A8, and Table A11
drop turnout camprally-effnosay allnone pidstr

**Save new version of 2017 Secularism Survey data (note: change file location to match where you are saving these data)
save "C:\Users\glayman\Dropbox\Secularism Project\POQ submission\Replication Files\sec2017_table2.dta", replace

**Reorder variables
order caseid weight none relatt relguide pray god bible factual philosci reason freemind nonrelguide secidnum decision advances knowledge problems pid ideol candeval govserv gaywed health immig world democ enviro terror govinv evol globwarm vaccine scitech sexed gaytherm prespray prestalk presend presgod estpled estten estpray estoff sex age evang mainline catholic educ income south white northeast west marry presvote

**For Mplus, recode all missing values to -99
mvencode _all, mv(-99)

**Save
save, replace

**Export to CSV file for Mplus
export delimited using "C:\Users\glayman\Dropbox\Secularism Project\POQ submission\Replication Files\sec2017_table2.csv", novarnames nolabel replace

**For all analyses in Table 2 (except political participation), Table A8, and Table A11, run the following models in MPlus
**Party ID model table 2
**Cultural issues model table 2
**Science issues model table 2
**Social welfare model table 2
**Nonisolate model table 2
**Immigration model table 2
**Candidate evaluations model table 2
**Presidential vote linear table 2
**table A8 CFA
**Presidential vote probit model_Table A11


**For political participation model in Table 2, re-open "Secularism Survey 2017_POQ_new.dta"
use "C:\Users\glayman\Dropbox\Secularism Project\POQ submission\Replication Files\Secularism Survey 2017_POQ_new.dta", clear

**Drop variables that aren't part of the political participation analysis
drop presvote ideol01-terror01 allnone pid01 candeval01 govserv01-world01 prespray-estoffrel

**Reorder variables
order caseid weight none relatt relguide pray god bible factual philosci reason freemind nonrelguide secidnum decision advances knowledge problems turnout camptalk camprally campbutton campwork campmoney sex age evang mainline catholic educ income south white pidstr effnosay northeast west marry

**For Mplus, recode all missing values to -99
mvencode _all, mv(-99)

**Save new version of 2017 Secularism Survey data (note: change file location to match where you are saving these data)
save "C:\Users\glayman\Dropbox\Secularism Project\POQ submission\Replication Files\sec2017_partic.dta", replace

**Export to CSV file for Mplus
export delimited using "C:\Users\glayman\Dropbox\Secularism Project\POQ submission\Replication Files\sec2017_partic.csv", novarnames nolabel replace

**For the political participation analysis in Table 2, run the following model in MPlus
**Political Participation model table 2


**For models in Table 1, Table A6, and Table A7, re-open "Secularism Survey 2017_POQ_new.dta"
use "C:\Users\glayman\Dropbox\Secularism Project\POQ submission\Replication Files\Secularism Survey 2017_POQ_new.dta", clear

**Drop variables that aren't part of the analysis in those tables
drop sex-marry white-estoffrel

**Reorder variables
order caseid nonrelguide relguide factual philosci reason freemind decision advances knowledge problems relatt pray god bible weight secidnum none allnone

**For Mplus, recode all missing values to -99
mvencode _all, mv(-99)

**Save new version of 2017 Secularism Survey data (note: change file location to match where you are saving these data)
save "C:\Users\glayman\Dropbox\Secularism Project\POQ submission\Replication Files\sec2017mplus1.dta", replace

**For Table A7 analysis (nones only), keep only if atheist, agnostic, or nothing in particular
keep if allnone==1

**Save new version of 2017 Secularism Survey data (note: change file location to match where you are saving these data)
save "C:\Users\glayman\Dropbox\Secularism Project\POQ submission\Replication Files\sec2017mplus_nones.dta", replace

**Export to CSV file for Mplus
export delimited using "C:\Users\glayman\Dropbox\Secularism Project\POQ submission\Replication Files\sec2017mplus_nones.csv", novarnames nolabel replace

**For the analysis in TableA7, run the following models in MPlus
**cfa_sec2017_allnones_1fac
**cfa_sec2017_allnones_2fac

**For Table 1 and Table A6 analyses, re-open "sec2017mplus1.dta"
use "C:\Users\glayman\Dropbox\Secularism Project\POQ submission\Replication Files\sec2017mplus1.dta", clear

**Drop allnone variable
drop allnone

**Export to CSV file for Mplus
export delimited using "C:\Users\glayman\Dropbox\Secularism Project\POQ submission\Replication Files\sec2017mplus1.csv", novarnames nolabel replace

**For Table 1 analyses, run the following models in Mplus
**cfa_sec2017_1fac
**cfa_sec2017_2fac

**For Table A6 analysis, run the following models in Mplus
**cfa_sec2017_secbel_1fac_rand
**cfa_sec2017_secbel_2fac_rand
**cfa_sec2017_secbel_1fac_nonrand

**END OF TABLES 1 & 2 ANALYSIS**








